package com.linkdood.app.schedule;

import com.linkdood.app.constants.SynchronizeConstants;
import com.linkdood.app.domain.ThirdParty;
import com.linkdood.app.service.impl.DdioSynchronize;
import com.linkdood.app.service.ThirdPartyService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

/**
 * 定时同步用户和组织架构任务
 *
 * @author hycao
 */
@Slf4j
@Component
public class SyncUserAndOrgTask extends QuartzJobBean {

    /**
     * 此处必须要使用 Autowired 或者 Setter， 不可以使用构造器
     */
    @Autowired
    private DdioSynchronize ddioSynchronize;
    @Autowired
    private ThirdPartyService thirdPartyService;

    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) {

        ThirdParty thirdParty = thirdPartyService.getDefaultThirdParty();

        // 全量同步 用户和组织架构
        log.info("Start sync user and organization schedule task");
        ddioSynchronize.syncUser(SynchronizeConstants.SYNC_TYPE_ALL, thirdParty);
        ddioSynchronize.syncOrg(SynchronizeConstants.SYNC_TYPE_ALL, thirdParty);
        log.info("End sync user and organization schedule task");

    }

}

